var app=angular.module('myApp', []).
  config(['$routeProvider', function($routeProvider) {
  $routeProvider.
      when('/', {templateUrl: 'report_conn_cnt.html', controller: ListExpMstCtrl}).      
      when('/cancel/', {templateUrl: 'report_conn_cnt.html', controller: ListExpMstCtrl}). 
      otherwise({redirectTo: '/'});
}]);


function ListExpMstCtrl($scope, $http,$window,$location,$filter)
 {
 
    $scope.currentPage = 0;
    $scope.pageSize = 25;
	$scope.Math = window.Math;
	$scope.ed = false;
	$scope.soc_arr = [];
	$scope.yr_arr = [];

    $http.get('report_conn_new_data.php').success(function(data) {	
		$scope.mismast = data;
		$scope.mismast_bkp = data;
		for(var i=0; i<data.length;i++){
			$scope.soc_arr[i] = data[i].soc;		
			$scope.yr_arr[i] = data[i].year;		
		}
		$scope.soc_arr = jQuery.unique( $scope.soc_arr );		
		$scope.soc_arr.sort();
		
		$scope.yr_arr = jQuery.unique( $scope.yr_arr );
		$scope.yr_arr.sort();
		$scope.yr_arr.reverse();
		$scope.yr_arr_bkp = $scope.yr_arr;
		$scope.search1 = $scope.yr_arr[0];
    });
	
	$scope.$watch('search2', function (newVal, oldVal) {
		if (oldVal == newVal) return;		
		$scope.chtype();		
	}, true);
	
	$scope.chtype=function()
	{	
		var newValue = $scope.search2;		
		if(newValue=='1')
			{						
				$http.get('report_conn_cut_data.php').success(function(data) {					
					$scope.mismast = data;
					for(var i=0; i<data.length;i++){
						$scope.soc_arr[i] = data[i].soc;		
						$scope.yr_arr[i] = data[i].year;		
					}
					$scope.soc_arr = jQuery.unique( $scope.soc_arr );		
					$scope.soc_arr.sort();
					
					$scope.yr_arr = jQuery.unique( $scope.yr_arr );
					$scope.yr_arr.sort();
					$scope.yr_arr.reverse();
					$scope.search1 = $scope.yr_arr[0];
				});
			}
			else
			{				
				$scope.mismast = $scope.mismast_bkp;					
				$scope.yr_arr = $scope.yr_arr_bkp;
			}
	}
	//Function to Clear 
    $scope.cancel= function()
	{
		$scope.activePath = null;
		$scope.activePath = $location.path('report_conn_cnt.php');
	};
      
 }
    
//Custom Filter Function to sort the record.
app.filter('startingFrom', function() 
{
    return function(input, start) 
    {
        start = +start; //parse to int
        return input.slice(start);
    };
});
	
	